<template>
    <div class="home">
        <HelloWorld></HelloWorld>
        <img src="@/assets/logo.png" alt="" />
        <hr />

        <button @click="$router.push('/ts')">ts目录</button>
        <!-- <p>{{ $store.state.a }}</p> -->
    </div>
</template>

<script lang="ts">
// defineComponent 函数，目的是定义一个组件，内部可传入一个配置对象
import { defineComponent, getCurrentInstance } from 'vue';
import HelloWorld from '@/components/HelloWorld.vue'; // @ is an alias to /src
import router from '../router/index';
import { useRoute, onBeforeRouteLeave } from 'vue-router';

export default defineComponent({
	name: 'Home',
	components: {
		HelloWorld
	},
	beforeRouteEnter(to, from, next) {
		next((vm: any) => {
			console.log('vm', vm);
			vm.data1 = 12354545;
		});
	},
	setup() {
		console.log(router, 6666666);

		onBeforeRouteLeave((to, from) => {
			console.log(to, '离开时触发***************************');
			// return false;
		});

		let { proxy: _this } = getCurrentInstance() as any; //获取上下文实例

		console.log(_this, 111222333);


		console.log(_this.$router, _this.$route);
		console.log(_this.$store, 1111111112222);

		_this.$store.state.a++;

		console.log(_this.$route);
		let route: any = useRoute();
		// console.log('vue3.0 route', route);


		function aaa():any {
			_this.$request
				.get(_this.api.fund.case(965), {
					aaa: '111',
					bbb: '2222'
				})
				.then((res: any) => {
					console.log(res, 'aaa1111');
				})
				.catch((err: any) => {
					console.log(err, 'aaa');
				});
		}
		aaa();
		async function ccc(e: any) {
			return _this.$request
				.get(e, {
					aaa: '111'
				})
				.then((res: any) => {
					return res;
				});
		}
		function ddd(): any {
			try {
				return Promise.all([ccc('/fund/case/965'), ccc('/fund/case/96500')])
					.then(res => {
						console.log(res, 1111);
						return res
					})
					.catch((err: any) => {
						console.log(err, 'Promise.all');
						throw new Error('22222');
					});
			} catch (error) {
				console.log(error, 45455);
			}
		}
		// ddd()
		// 	.then((res: any) => {
		// 		console.log(res);
		// 		console.log(222222);
		// 	})
		// 	.catch((err: any) => {
		// 		console.log(err, 666666);
		// 	});
		
		function getAreaList():any {
			_this.$request.post('https://api.kags.cn' + '/v1/home/area_community_region', {
				getAreaList: '111111111111'
			}).then((res: any) => {
				console.log( res, 1111111111 );
			})
		}
		getAreaList()

		return {
			aaa: 111,
			ccc,
		};
	}
	// data() {
	// 		return {
	// 				data1: 123,
	// 		};
	// },
	// created() {
	// 		// console.log("vue2", this);
	// 		setTimeout(() => {
	// 				console.log(this.data1, 11111111);
	// 		}, 2000);
	// },
});
</script>
